//
// @author				mitchell
// @description		020101.html页面的JS打包文件 注意引用顺序
// @lastmodified		$2010-7 - 15$
$(document).ready(function(){
	// res_url
	if (js_context && js_context.res_url) {
		js_context.res_url = function() {
			var res_url = js_context.res_url;
			var func = function(path) {
				var url = res_url;
				path = !path ? "" : path.replace(/(.+?)\.(js|css|jpg|gif|png|cur)$/i, "$1"+(js_context.jsrevision || "")+".$2");
				return url + path;
			};
			func.toString = function() {
				return res_url;
			};
			func.get = func;
			return func;
		}();
	}
	
	//search type
	$(".option_pic").click(function(event){
		event.preventDefault();
		var div = $(this).attr("type");
		$(".option_pic").show();
		$("."+div).hide();
		if(div == "pic_xs"){
			$(".option").html("展开选项");
			$(".bus2-2").slideUp(800);
		}else{
			$(".option").html("隐藏选项");
			$(".bus2-2").slideDown(800);
		}
	});
	
	var map;
	var order_taid = js_context.taid;
	var order_somoid = js_context.somoid;
	var keyword_store = js_context.keyword_store; 
	var index_s = js_context.index_s;
	var marker_arr = js_context.marker;
	var s = js_context.s;
	var lat = js_context.lat;
	var lng = js_context.lng;
	
	//marker;
	var marker_arr = js_context.marker;
	var OLatlngs = [];
	var markers = {};
	//layer
	if(marker_arr != undefined && marker_arr.length>0){
		var html = '';
		var div = '';
		if( $(".shop1:first").attr("num") != 1){
			html = $(".shop-blo:first").html();
			div = $(".shop-blo:first");
		}else{
			html = $(".shop1:first").html();
			div = $(".shop1:first");
		}
		$("#layer_store").html( html );
		var layer = js_context.layer;
		$(".layer_"+layer).show();
		if($("."+layer).attr("num") == 1){
			$("."+layer).click(function(event){
				event.preventDefault();
				var _this = this;
				var type = $(".layer_"+layer).attr("type");
				var url =js_context.base_url+"ajax/account/pic_layer";
	
				$.get(url,{"type" : type}, function(result){
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					$(".out_wk,.layer_"+layer+", .layer1_"+layer).hide();
				},"json");
			});
		}
		if($(".layer_"+layer).is(":visible")){
			var top = div.offset().top;
			var left = div.offset().left;
			var top1 = $(".guid_ss1").offset().top;
			var layer_top = $(".out_wk").offset().top;
			height = layer_top-(top1-top);
			$(".out_wk").css('top',height).css('left',-3);
		}
	}
	
	function creat_map(latitude,longitude){
		//默认中心位置
		latlng = new google.maps.LatLng(39.9579201,116.3876719);
		var myOptions = {
			    zoom: 12,
			    center: latlng,
			    mapTypeId: 'roadmap',
			    mapTypeControl:false,
			    streetViewControl:false,
			    navigationControl:true,
//			    navigationControlOptions: {
//			        style: google.maps.NavigationControlStyle.ZOOM_PAN,
//			        position: google.maps.ControlPosition.TOP_LEFT
//			    },
			    scaleControl: true 
		};
		map = new google.maps.Map(document.getElementById("search_map"), myOptions);
	}
	
	if(js_context.showmap){
		if(marker_arr != undefined && marker_arr.length>0){
			creat_map();
			for(var i=0;i<marker_arr.length;i++){
				
				makeMarker(marker_arr[i].lat,marker_arr[i].lng,marker_arr[i].name,marker_arr[i].sid,i+1);
			}
			var LatLngBounds = new google.maps.LatLngBounds();
			for (var i in OLatlngs){
				LatLngBounds.extend(OLatlngs[i]);
			}		
			map.fitBounds( LatLngBounds );
			//if(map.getZoom()>14)map.setZoom(14);
			map.setCenter();
		}
		
		if(js_context.lat && js_context.lng){
			user_latlng = new google.maps.LatLng(js_context.lat,js_context.lng);
			position_marker = new google.maps.Marker({
				icon: js_context.res_url('images/marker/tlpc.gif'),
				map: map,
				draggable: true,
			    position: user_latlng
			});
		}
	}else{
		$("#search_map").remove(); 
	}
	
	function makeMarker(latitude,longitude,title,cacheid,tagicon){
		var OLatlng = new google.maps.LatLng(latitude,longitude);
		tagicon = (tagicon=='')?'loc':tagicon;
		var img = js_context.res_url('images/marker/tlpc.gif');
		//var marker = new google.maps.Marker({map: map, position: OLatlng,title:title, icon: img });
		var marker = new google.maps.Marker({map: map, position: OLatlng,title:title });
		OLatlngs[cacheid] = OLatlng;
		marker.cacheid = cacheid;
		marker.tagicon = tagicon;
		markers[cacheid] = marker;
		google.maps.event.addListener(marker, 'click', function(LatLng) {
			show_storeinfo(cacheid,title,tagicon);
			$(".store_"+cacheid).removeClass("seek-fruit");
			$(".store_"+cacheid).addClass("seek-fruit1");
			$('.seek-fruit1').not(".store_"+cacheid).addClass('seek-fruit').removeClass("seek-fruit1");
		});
		google.maps.event.addListener(marker, 'mouseout', function(){
//			if(marker_cacheid != tagicon){
//				marker.setIcon(js_context.res_url('images/marker/tlpc.gif'));
//			}
		});
		google.maps.event.addListener(marker, 'mouseover', function(){
//			if(marker_cacheid != tagicon){
//				marker.setIcon(js_context.res_url('images/marker/h'+tagicon+'.gif'));
//				$(".store_"+cacheid).removeClass("seek-fruit");
//				$(".store_"+cacheid).addClass("seek-fruit1");
//			}
		});
	}
	
	
	
	//new order
	$("#store_order").change(function(){
		var order = $(this).children('option:selected').val();
		if(s){
			self.location = js_context.base_url+"search?address="+index_s+"&s=s&order="+order+"&lat="+lat+"&lng="+lng;
			return false;
		}
		if(order==0){
			return false;
		}
		if(order_taid != null){
			self.location = js_context.base_url+'search?taid='+order_taid+"&order="+order+"#position";
			return false;
		}
		if(order_somoid != null){
			self.location = js_context.base_url+'search?somoid='+order_somoid+"&order="+order+"#position";
			return false;
		}
		if(keyword_store != null){
			self.location = js_context.base_url+'search?store_q='+keyword_store+"&order="+order+"#position";
			return false;
		}
	});
	//right store_content_list
	$(".btn1").click(function(event){
		event.preventDefault();
		$("#storemap,.map-tip,.map-tip1,#xfdt").hide();
		var _this = this;
		var type = $(_this).attr("typeid");
		var sid = $(_this).attr("sid");
		var Ajax_url = js_context.base_url+"ajax/search/get_store";
		var num = $(_this).attr("num");
		var height = (num-1)*178;
		var url = $(_this).attr("url");
		$(".right_store_loading").show();	
		$("#shop-pop-dish").css("margin-top",height).show();
		$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
		//div 滑动置顶
		var count = Number($(".storecount").html());
		if(count > 3){
			var h = $(".shop_"+sid).offset().top;
			//var s = $(document).scrollTop();
			//alert($(document).height());
		    $('html,body').animate({ scrollTop:h },1000)
		}
		//food
		$(".right_store").hide();
		if(sid == $(".foodlist_"+sid).attr("sid")){
			$(".foodlist_"+sid).show();
			$(".right_store_loading").hide();
			return false;
		}
		
		if(type == "food"){
			$.get(Ajax_url,{"sid" : sid,"type" : type},function(result){
				$(".right_store_loading").hide();
				if(result.success == false){
					alert('通讯失败');
					return false;
				}
				var data = result.message;
				if(!data){
					alert('查询失败');
				}
				var html = '';
				
				if(data.length==0){
					html += "<div class='right_store foodlist_"+result.sid+"' sid='"+result.sid+"'>";
					html += '<div id="shop-rev">';
					html += "<div class='shop-pop2-min1'>";
					html += "<ul>";
					html += "本餐厅暂无餐品,等待店家添加";
					html += "</div>";
					html += "</ul>";
					html += "</div>";
					html += "</div>";
				}else{
					html += "<div class='right_store foodlist_"+result.sid+"' sid='"+result.sid+"'>";
					html += '<div id="shop-rev">';
					html += "<div class='shop-pop2-min1'>";
					html += "<ul>";
					for(var i=0;i<data.length;i++){
						html += "<li><span><a href='"+js_context.base_url+"food/"+data[i].fid+"' title="+data[i].foodname+">"+data[i].foodname.substr(0,10)+"</a></span><font>￥"+data[i].price+"</font></li>";
					}
					html += "</ul>";
					html += "</div>";
					html += "</div>";
					html += "<div class='shop-pop2-a'>";
					html += '<input type="button" onclick="location=\''+js_context.base_url+'store/'+result.sid+'\'" value="" />';
					html += "</div>";
					html += "</div>";
				}
				$("#shoparr").append(html).show();
				
			},"json");
		}
	});
	
	$(".btn2").click(function(event){
		event.preventDefault();
		$("#storemap,.map-tip,.map-tip1,#xfdt").hide();
		var _this = this;
		var type = $(_this).attr("typeid");
		var sid = $(_this).attr("sid");
		var Ajax_url = js_context.base_url+"ajax/search/get_store";
		var num = $(_this).attr("num");
		var height = (num-1)*178;
		var url = $(_this).attr("url");
		$(".right_store_loading").show();
		$("#shop-pop-dish").css("margin-top",height).show();
		$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
		var count = Number($(".storecount").html());
		if(count > 3){
			var h = $(".shop_"+sid).offset().top;
		    $('html,body').animate({ scrollTop:h },1000);
		}
		//store_comment
		$(".right_store").hide();
		if(sid == $(".no_comment_"+sid).attr("sid")){
			$(".no_comment_"+sid).show();
			$(".right_store_loading").hide();
			return false;
		}
		$(".right_store").hide();
		if(sid == $(".comment_"+sid).attr("sid")){
			$(".comment_"+sid).show();
			$(".right_store_loading").hide();
			return false;
		}
		if(type == "store_comment"){
			$.get(Ajax_url,{"sid" : sid,"type" : type},function(result){
				$(".right_store_loading").hide();
				if(result.success == false){
					alert('通讯失败');
					return false;
				}
				var data = result.message;
				if(!data){
					alert('查询失败');
					return false;
				}
				var html = '';
			
				if(data.length==0){
					html += "<div class='right_store no_comment_"+sid+"' sid='"+sid+"'>";
					html += '<div id="shop-rev">';
					html += "<div class='shop-norev'>";
					html += "该餐厅暂无评论。";
					html += "</div>";
					html += "</div>";
					html += "</div>";
				}else{
					html += "<div class='right_store comment_"+sid+"' sid='"+sid+"'>";
					html += '<div id="shop-rev">';
					html += "<div class='shop-rev'>";
					for(var i=0;i<data.length;i++){
						html += "<div class='shop-rev1'><div class='shop-rev1-1'>";
						html += "<div class='score-1'></div></div><div class='shop-rev1-2'>"
						html += "<p>"+data[i].content+"</p>";	
						html += "</div><div class='shop-rev1-3'>";
						html += "<a href='"+js_context.base_url+"'>外卖网</a>";
						html += "<span>"+data[i].commname+"</span></div></div>";
					}
					html += "</div>";
					html += '</div>';	
					html += '<div class="shop-rev-a">';
					html += '<a href="'+js_context.base_url+'/store/'+sid+'?type=s_comment#d_position">查看更多评价</a>';
					html += "</div>";
				}
				$("#shoparr").append(html);
			},"json");	
		}
	});
	
	$(".btn3").click(function(event){
		event.preventDefault();
		$("#storemap,.map-tip,.map-tip1,#xfdt").hide();
		var _this = this;
		var type = $(_this).attr("typeid");
		var sid = $(_this).attr("sid");
		var Ajax_url = js_context.base_url+"ajax/search/get_store";
		var num = $(_this).attr("num");
		var height = (num-1)*178;
		var url = $(_this).attr("url");
		$(".right_store_loading").show();
		$("#shop-pop-dish").css("margin-top",height).show();
		$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
		var count = Number($(".storecount").html());
		if(count > 3){
			var h = $(".shop_"+sid).offset().top;
		    $('html,body').animate({ scrollTop:h },1000);
		}
	    //store_content
		$(".right_store").hide();
		if(sid == $(".content_"+sid).attr("sid")){
			$(".content_"+sid).show();
			$(".right_store_loading").hide();
			return false;
		}
		if(type == "store_content" ){
			$.get(Ajax_url,{"sid" : sid,"type" : type},function(result){
				$(".right_store_loading").hide();
				if(result.success == false){
					alert('通讯失败');
					return false;
				}
				var data = result.message;
				if(!data){
					alert('查询失败');
				}
				var html = '';
					html +='<div class="right_store content_'+sid+'" sid='+sid+'>';
					html +='<div id="shop-rev">';
					html += "<div class='shop-rat'><div class='shop-rat-add'>";
					html +=	"<div class='favorite_star ";
					if(result.collect){html+='favorite_star';}
					html += "'><a href='javascript:void(0)'>";
					html += "</a></div>";
					html +=	"<h1>地址：</h1><ul>";
					html +=	"<li>"+data.address+"</li>";
					html +=	"</ul></div>";	
					html +=	"";
					var mincost = data.mincost==''?'不限':data.mincost;
					html += "<div class='answer-time'><span>起送价：</span><font>"+mincost+"</font><label></label></div>";
					var score = (data.rank/20<1)?1:data.rank/20;
					html += "<div class='shop-rating'><h1><font style='margin-left:-10px'>评级：</font><div class='score-"+score+"'></div></h1>";
					//html += "<div class='shop-rating1'>";	
					//html += "<p><span>2</span><font>餐厅评级</font></p>";		
					//html += "<p><span>2</span><font>菜品质量</font></p>";			
					//html += "<div style='clear:both;'></div></div>";
					html += "</div><div class='shop-hours'><h1>营业时间：</h1>";			
					html += "<ul>";
					if(data.selltime=="" || data.selltime=='day'){
						html +=	"<li>-</li>";
					}else{
						html +=	"<li>"+data.selltime+"</li>";
					}
					
					html +=	"</ul></div>";
					html += "<div class='shop-hours-cou'>";	
					html += "";			
					html +=	"</div></div>";
					html += "<div class='shop-hours-a'>";
					html += '<input type="button" onclick="location=\''+js_context.base_url+'store/'+sid+'\'" value="" />';
					//html += "<a href='javascript:void(0)'><img src='"+js_context.base_url+"res/images/shop-hours.png' /></a>";
					html += "</div>";
					html += "</div>";
					html += "</div>";
				
				$("#shoparr").append(html);
			},"json");	
		}
	});
	$(".btn4").click(function(event){
		event.preventDefault();
		$("#storemap,.map-tip,#xfdt").hide();
		var _this = this;
		var type = $(_this).attr("typeid");
		var sid = $(_this).attr("sid");
		var Ajax_url = js_context.base_url+"ajax/search/get_store";
		var num = $(_this).attr("num");
		var height = (num-1)*178;
		var url = $(_this).attr("url");
		$(".right_store_loading").show();
		$("#shop-pop-dish").css("margin-top",height).show();
		$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
		var count = Number($(".storecount").html());
		if(count > 3){
			var h = $(".shop_"+sid).offset().top;
		    $('html,body').animate({ scrollTop:h },1000);
		}
	    //Coupons
		$(".right_store").hide();
		if(sid == $(".Coupons_"+sid).attr("sid")){
			$(".Coupons_"+sid).show();
			$(".right_store_loading").hide();
			return false;
		}
		if(type == "Coupons" ){
			$(".right_store_loading").hide();
			var html = '';
			html += "<div class='right_store Coupons_"+sid+"' sid="+sid+">";
			html += '<div id="shop-rev">';
			html += "<div class='shop-coupon'>暂时没有优惠券</div>";
			html += "<div class='shop-couponu'><ul>";
			html += "<li>预订优惠</li><li>预订优惠</li>";
			html += "</ul></div>";
			html += "</div>";
			html += "</div>";
			$("#shoparr").append(html);
		}
	});
	
	$(".shop-close").click(function(event){
		event.preventDefault();
		$("#shop-pop-dish").hide();
		$("#storemap,.map-tip,.map-tip1,#xfdt").show();
	});

    //store Load
    var order = js_context.order;
    $(".store_load").click(function(event){
    	event.preventDefault();
    	var page = $(".page").val();
    	var typeid = $(".page").attr("typeid");
    	var types = $(".page").attr("types");
		var lat = $(".page").attr("lat");
		var lng = $(".page").attr("lng");
    	var url = js_context.base_url+"ajax/search/get_search_store";
    	$.get(url,{"lng":lng ,"lat":lat,"typeid" : typeid ,"types" : types , order: order, "page" : (Number(page)+1)},function(result){
    		if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				$(".uploading1").hide();
				return false;
			}
			
			var html = "";
			for(var i=0;i<data.length;i++){
				if(data[i].opentime <= Number(result.newtime) && Number(result.newtime) <= data[i].closetime || data[i].closetime == 0){
					html += '<div class="shop1 shop_'+data[i].sid+'">';
					html += '<div class="shop1-1">';
					html += '<a href="'+js_context.base_url+'store/'+data[i].sid+'"><img src="'+js_context.base_url+'res/images/shop1.gif" /></a>';
					html += '</div>';
					html += '<div class="shop1-2">';
					if(types == "keyword"){
						html += '<h2><a href="'+js_context.base_url+'store/'+data[i].sid+'">'+(i+1+20*page)+'.'+data[i].name.replace(typeid,'<B style="color:red">'+typeid+'</B>')+'</a></h2>';
					}else{
						html += '<h2><a href="'+js_context.base_url+'store/'+data[i].sid+'">'+(i+1+20*page)+'.'+data[i].name+'</a></h2>';
					}
					html += '<div class="tiny">';
					html += '<div class="score-';
					if(data[i].rank!=null && data[i].rank!=0){
						html += Math.ceil(data[i].rank/20)+'">';
					}else{
						html += 1+'">';
					}
					html += '</div></div>';
					html +=	'<div class="shop-intro">电话：';
					if(data[i].tel400 != ''){
						html += '400-010-1114 (转)<label> '+data[i].tel400+'</label>';
					}else{
						html += data[i].tel;
					}
					html += '</div>';
					html +=	'<div class="shop-view">';
					//onclick
					html += '<input type="button"  value="" onclick="location=\''+js_context.base_url+'store/'+data[i].sid+'\'"/>';
					html +=	'</div>';
					html +=	'<div class="shop-time">';
					//servecost
					
					html +=	'<div class="shop-time1">送餐费用:';
					if(data[i].servecost!=0 && data[i].servecost!='免费'){
						html += '￥'+data[i].servecost;
					}else{
						html += '免运费';
					}
					html += '</div>';
					html += '<div class="shop-time1">';
					if(data[i].mincost!=""){
						html += data[i].mincost;
					}else{
						html += '不限';
					}
					html += '起送</div>';
					if(s == 's'){
						html += '<div class="shop-time1">订单量：<span>'+data[i].ordernumber+'</span>单</div>';
					}
					html += '<a class="store_map"  latitude="'+data[i].latitude+'" longitude="'+data[i].longitude+'" href="'+js_context.base_url+'store/'+data[i].sid+'?type=s_content#d_position">查看地图</a>';
					html +=	'</div></div>';
					html += '<div class="shop1-3">';
					//url sid
					html +='<input url="'+js_context.base_url+'store/'+data[i].sid+'" class="store_content_list btn1_'+page+'" typeid="food" sid="'+data[i].sid+'" num='+(i+1+20*page)+' name="button" type="button" value="主打菜品" />';
					html +='<input url="'+js_context.base_url+'store/'+data[i].sid+'" class="store_content_list btn2_'+page+'" typeid="store_comment" sid="'+data[i].sid+'" num='+(i+1+20*page)+' type="button" value="评价" />';
					html += '<input class="store_content_list btn3_'+page+'" typeid="store_content" sid="'+data[i].sid+'" num='+(i+1+20*page)+' type="button" value="餐厅信息" />';
					html += '<input class="store_content_list btn4_'+page+' hide" typeid="Coupons" sid="'+data[i].sid+'" num='+(i+1+20*page)+' type="button" value="优惠券(0)" />';
					html += '</div></div>';
				}else{
					html += '<div class="shop-blo storeclose shop_'+data[i].sid+'" style="height:148px">'; 
					html += '<div class="shop2 ">';
					html += '<div class="shop2-1">';
					html += '<a href="'+js_context.base_url+'store/'+data[i].sid+'"><img src="'+js_context.base_url+'res/images/shop1.gif" /></a>';
					html += '</div>';
					html += '<div class="shop2-2">';
					if(types == "keyword"){
						html += '<h2><a href="'+js_context.base_url+'store/'+data[i].sid+'">'+(i+1+20*page)+'.'+data[i].name.replace(typeid,'<B style="color:red">'+typeid+'</B>')+'</a></h2>';
					}else{
						html += '<h2><a href="'+js_context.base_url+'store/'+data[i].sid+'">'+(i+1+20*page)+'.'+data[i].name+'</a></h2>';
					}
					html += '<div class="tiny">';
					html += '<div class="score-';
					if(data[i].rank!=null && data[i].rank!=0){
						html += Math.ceil(data[i].rank/20)+'">';
					}else{
						html += 1+'">';
					}
					html += '</div></div>';
					html +=	'<div class="shop-intro">电话：';
					if(data[i].tel400 != ''){
						html += '400-010-1114 (转)<label> '+data[i].tel400+'</label>';
					}else{
						html += data[i].tel;
					}
					html += '</div>';
					html +=	'<div class="shop-view">';
					//onclick
					html += '<input type="button"  value="" onclick="location=\''+js_context.base_url+'store/'+data[i].sid+'\'"/>';
					html +=	'<div class="rest_mid">休息中...</div></div>';
					html +=	'<div class="shop-time">';
					//servecost
					
					html +=	'<div class="shop-time1">送餐费用:';
					if(data[i].servecost!=0 && data[i].servecost!='免费'){
						html += '￥'+data[i].servecost;
					}else{
						html += '免运费';
					}
					html += '</div>';
					html += '<div class="shop-time1">';
					if(data[i].mincost!=""){
						html += data[i].mincost;
					}else{
						html += '不限';
					}
					html += '起送</div>';
					if(s == 's'){
						html += '<div class="shop-time1">订单量：<span>'+data[i].ordernumber+'</span>单</div>';
					}
					html += '<a class="store_map"  latitude="'+data[i].latitude+'" longitude="'+data[i].longitude+'" href="'+js_context.base_url+'store/'+data[i].sid+'?type=s_content#d_position">查看地图</a>';
					html +=	'</div></div>';
					html += '<div class="shop2-3">';
					//url sid
					html +='<input url="'+js_context.base_url+'store/'+data[i].sid+'" class="store_content_list btn1_'+page+'" typeid="food" sid="'+data[i].sid+'" num='+(i+1+20*page)+' name="button" type="button" value="主打菜品" />';
					html +='<input url="'+js_context.base_url+'store/'+data[i].sid+'" class="store_content_list btn2_'+page+'" typeid="store_comment" sid="'+data[i].sid+'" num='+(i+1+20*page)+' type="button" value="评价" />';
					html += '<input class="store_content_list btn3_'+page+'" typeid="store_content" sid="'+data[i].sid+'" num='+(i+1+20*page)+' type="button" value="餐厅信息" />';
					html += '<input class="store_content_list btn4_'+page+' hide" typeid="Coupons" sid="'+data[i].sid+'" num='+(i+1+20*page)+' type="button" value="优惠券(0)" />';
					html += '</div></div></div>';
				}
			}
			$(".search_shop_list").append(html);
			$(".page").val(Number(page)+1);
			if(data.length<20){
				$(".uploading1").hide();
				//return false;
			}
			/*******map***************/
			$('.store_map').click(function(event){
			  	event.preventDefault();
			  	var s = $(document).scrollTop();
				$(".map1").css("top",s+30).css("left",100).show();
				$("#map").show();
				
				var latitude = $(this).attr('latitude');
				var longitude = $(this).attr('longitude');
				latlng = new google.maps.LatLng(latitude,longitude);
				var myOptions = {
					    zoom: 16,
					    center: latlng,
					    mapTypeId: 'roadmap',
					    mapTypeControl:false,
					    streetViewControl:false,
					    navigationControl:false
				};
				var map = new google.maps.Map(document.getElementById("map"), myOptions);
				$(".map").not($(this)).each(function(event){
					var ll = new google.maps.LatLng($(this).attr('latitude') ,$(this).attr('longitude'));
					var marker = new google.maps.Marker({
				 		map: map,
				 		position: ll
				    });
				});
				var image = new google.maps.MarkerImage('../res/images/marker_greenA.png');

				var marker = new google.maps.Marker({
					icon: image,
			 		map: map,
			 		position: latlng
			    });
		  });
			//right store_content_list
				
			$(".btn1_"+page).click(function(event){
				event.preventDefault();
				$(".map-tip,.map-tip1,#xfdt").hide();
				var _this = this;
				var type = $(_this).attr("typeid");
				var sid = $(_this).attr("sid");
				var Ajax_url = js_context.base_url+"ajax/search/get_store";
				var num = $(_this).attr("num");
				var height = (num-1)*178;
				var url = $(_this).attr("url");
				$(".right_store_loading").show();	
				$("#shop-pop-dish").css("margin-top",height).show();
				$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
				
				var h = $(".shop_"+sid).offset().top;
			    $('html,body').animate({ scrollTop:h },1000);
				//food
				$(".right_store").hide();
				if(sid == $(".foodlist_"+sid+"_"+num).attr("sid")){
					$(".foodlist_"+sid+"_"+num).show();
					$(".right_store_loading").hide();
					return false;
				}
				
				if(type == "food"){
					$.get(Ajax_url,{"sid" : sid,"type" : type},function(result){
						$(".right_store_loading").hide();
						if(result.success == false){
							alert('通讯失败');
							return false;
						}
						var data = result.message;
						if(!data){
							alert('查询失败');
							return false;
						}
						var html = '';
						if(data.length==0){
							html += "<div class='right_store foodlist_"+result.sid+"_"+num+"' sid='"+result.sid+"'>";
							html += '<div id="shop-rev">';
							html += "<div class='shop-pop2-min1'>";
							html += "<ul>";
							html += "本餐厅暂无餐品,等待店家添加";
							html += "</div>";
							html += "</ul>";
							html += "</div>";
							html += "</div>";
						}else{
							html += "<div class='right_store foodlist_"+result.sid+"_"+num+"' sid='"+result.sid+"'>";
							html += '<div id="shop-rev">';
							html += "<div class='shop-pop2-min1'>";
							html += "<ul>";
							for(var i=0;i<data.length;i++){
								html += "<li><span><a href='"+js_context.base_url+"food/"+data[i].fid+"' title="+data[i].foodname+">"+data[i].foodname.substr(0,10)+"</a></span><font>￥"+data[i].price+"</font></li>";
							}
							html += "</ul>";
							html += "</div>";
							html += "</div>";
							html += "<div class='shop-pop2-a'>";
							html += '<input type="button" onclick="location=\''+js_context.base_url+'store/'+result.sid+'\'" value="" />';
							html += "</div>";
							html += "</div>";
						}
						$("#shoparr").append(html).show();
					},"json");
				}
			});
			
			$(".btn2_"+page).click(function(event){
				event.preventDefault();
				$(".map-tip,.map-tip1,#xfdt").hide();
				var _this = this;
				var type = $(_this).attr("typeid");
				var sid = $(_this).attr("sid");
				var Ajax_url = js_context.base_url+"ajax/search/get_store";
				var num = $(_this).attr("num");
				var height = (num-1)*178;
				var url = $(_this).attr("url");
				$(".right_store_loading").show();
				$("#shop-pop-dish").css("margin-top",height).show();
				$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
				
				var h = $(".shop_"+sid).offset().top;
			    $('html,body').animate({ scrollTop:h },1000);
				//store_comment
				$(".right_store").hide();
				if(sid == $(".no_comment_"+sid).attr("sid")){
					$(".no_comment_"+sid).show();
					$(".right_store_loading").hide();
					return false;
				}
				$(".right_store").hide();
				if(sid == $(".comment_"+sid).attr("sid")){
					$(".comment_"+sid).show();
					$(".right_store_loading").hide();
					return false;
				}
				if(type == "store_comment"){
					$.get(Ajax_url,{"sid" : sid,"type" : type},function(result){
						$(".right_store_loading").hide();
						if(result.success == false){
							alert('通讯失败');
							return false;
						}
						var data = result.message;
						if(!data){
							alert('查询失败');
						}
						var html = '';
						if(data.length==0){
							html += "<div class='right_store no_comment_"+sid+"' sid='"+sid+"'>";
							html += '<div id="shop-rev">';
							html += "<div class='shop-norev'>";
							html += "该餐厅暂无评论。";
							html += "</div>";
							html += "</div>";
							html += "</div>";
						}else{
							html += "<div class='right_store comment_"+sid+"' sid='"+sid+"'>";
							html += '<div id="shop-rev">';
							html += "<div class='shop-rev'>";
							for(var i=0;i<data.length;i++){
								html += "<div class='shop-rev1'><div class='shop-rev1-1'>";
								html += "<div class='score-1'></div></div><div class='shop-rev1-2'>"
								html += "<p>"+data[i].content+"</p>";	
								html += "</div><div class='shop-rev1-3'>";
								html += "<a href='"+js_context.base_url+"'>外卖网</a>";
								html += "<span>"+data[i].commname+"</span></div></div>";
							}
							html += "</div>";
							html += '</div>';
							html += '<div class="shop-rev-a">';
							html += '<a href="'+js_context.base_url+'/store/'+sid+'?type=s_comment#d_position">查看更多评价</a>';	
							html += "</div>";
						}
						$("#shoparr").append(html);
					},"json");	
				}
			});
			
			$(".btn3_"+page).click(function(event){
				event.preventDefault();
				$(".map-tip,.map-tip1,#xfdt").hide();
				var _this = this;
				var type = $(_this).attr("typeid");
				var sid = $(_this).attr("sid");
				var Ajax_url = js_context.base_url+"ajax/search/get_store";
				var num = $(_this).attr("num");
				var height = (num-1)*178;
				var url = $(_this).attr("url");
				$(".right_store_loading").show();
				$("#shop-pop-dish").css("margin-top",height).show();
				$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
				
				var h = $(".shop_"+sid).offset().top;
			    $('html,body').animate({ scrollTop:h },1000);
				//store_content
				$(".right_store").hide();
				if(sid == $(".content_"+sid).attr("sid")){
					$(".content_"+sid+"_"+num).show();
					$(".content_"+sid).show();
					$(".right_store_loading").hide();
					return false;
				}
				if(type == "store_content" ){
					$.get(Ajax_url,{"sid" : sid,"type" : type},function(result){
						$(".right_store_loading").hide();
						if(result.success == false){
							alert('通讯失败');
							return false;
						}
						var data = result.message;
						if(!data){
							alert('查询失败');
						}
						var html = '';
						html +='<div class="right_store content_'+sid+'" sid='+sid+'>';
						html +='<div id="shop-rev">';
						html += "<div class='shop-rat'><div class='shop-rat-add'>";
						html +=	"<div class='favorite_star'><a href='javascript:void(0)'>";
						html += "</a></div>";
						html +=	"<h1>地址：</h1><ul>";
						html +=	"<li>"+data.address+"</li>";
						html +=	"</ul></div>";	
						html +=	"";
						var mincost = data.mincost==''?'不限':data.mincost;
						html += "<div class='answer-time'><span>起送价：</span><font>"+mincost+"</font><label></label></div>";
						var score = (data.rank/20<1)?1:result.rank/20;
						html += "<div class='shop-rating'><h1><font>评级：</font><div class='score-"+score+"'></div></h1>";
						//html += "<div class='shop-rating1'>";	
						//html += "<p><span>2</span><font>餐厅评级</font></p>";		
						//html += "<p><span>2</span><font>菜品质量</font></p>";			
						//html += "<div style='clear:both;'></div></div>";
						html += "</div><div class='shop-hours'><h1>营业时间：</h1>";			
						html += "<ul>";
						if(data.selltime=="" || data.selltime=='day'){
							html +=	"<li>-</li>";
						}else{
							html +=	"<li>"+data.selltime+"</li>";
						}
						
						html +=	"</ul></div>";
						html += "<div class='shop-hours-cou'>";	
						html += "";			
						html +=	"</div></div>";
						html += "<div class='shop-hours-a'>";
						html += '<input type="button" onclick="location=\''+js_context.base_url+'store/'+sid+'\'" value="" />';
						//html += "<a href='javascript:void(0)'><img src='"+js_context.base_url+"res/images/shop-hours.png' /></a>";
						html += "</div>";
						html += "</div>";
						html += "</div>";
					
					$("#shoparr").append(html);
					},"json");	
				}
			});
			$(".btn4_"+page).click(function(event){
				event.preventDefault();
				$(".map-tip,.map-tip1,#xfdt").hide();
				var _this = this;
				var type = $(_this).attr("typeid");
				var sid = $(_this).attr("sid");
				var Ajax_url = js_context.base_url+"ajax/search/get_store";
				var num = $(_this).attr("num");
				var height = (num-1)*178;
				var url = $(_this).attr("url");
				$(".right_store_loading").show();
				$("#shop-pop-dish").css("margin-top",height).show();
				$("#shop-pop-dish .shop-pop2>h1>font ").html($(_this).val());
				
				var h = $(".shop_"+sid).offset().top;
			    $('html,body').animate({ scrollTop:h },1000);
				//Coupons
				$(".right_store").hide();
				if(sid == $(".Coupons_"+sid).attr("sid")){
					$(".Coupons_"+sid).show();
					$(".right_store_loading").hide();
					return false;
				}
				if(type == "Coupons" ){
					$(".right_store_loading").hide();
					var html = '';
					html += "<div class='right_store Coupons_"+sid+"' sid="+sid+">";
					html += '<div id="shop-rev">';
					html += "<div class='shop-coupon'>暂时没有优惠券</div>";
					html += "<div class='shop-couponu'><ul>";
					html += "<li>预订优惠</li><li>预订优惠</li>";
					html += "</ul></div>";
					html += "</div>";
					html += "</div>";
					$("#shoparr").append(html);
				}
			});
			//////////////////////
    	},"json");
    });
    
  //map
	var isIE=!!window.ActiveXObject;
	var isIE6 = isIE&&!window.XMLHttpRequest;
	if(isIE6){
		return false;
	}
	
	//right map
	var map_box = $("#storemap");
	trip_map = function() {
        var st = $(document).scrollTop();
        var height = st;
       // console.log(height);
        var width = $(window).width()/2 + 205;
        if(st > 558){
        	$("#storemap").attr("id","xfdt");
        	$("#shop-map").attr("id","shop-map1");
        	map_box.css("left", width);
        }else{
        	$("#xfdt").attr("id","storemap");
        	$("#shop-map1").attr("id","shop-map");
        }
    };
    $(window).bind("scroll", trip_map);
    /*
    //右侧提示框
    var shopcar_box = $("#xf_tip");
	trip_shopcar = function() {
        var st = $(document).scrollTop();
        var height = st;
       // console.log(height);
        var width = $(window).width()/2 + 205;
        if(st > 558){
        	$("#xf_tip").attr("id","map-tip1");
        	$(".map-tip").attr("class","map-tip1");
			shopcar_box.css("left", width);
        }else{
        	$("#map-tip1").attr("id","xf_tip");
        	$(".map-tip1").attr("class","map-tip");
        }
    };
   
    $(window).bind("scroll", trip_shopcar);
     */
    $(".shopdp_map").click(function(event){
    	event.preventDefault();
    	$(".map1").hide();
    });
    $('.store_map').click(function(event){
	  	event.preventDefault();
		var s = $(document).scrollTop();
		$(".map1").css("top",s+30).css("left",100).show();
		$("#map").show();
	  	
		var latitude = $(this).attr('latitude');
		var longitude = $(this).attr('longitude');
		latlng = new google.maps.LatLng(latitude,longitude);
		var myOptions = {
			    zoom: 16,
			    center: latlng,
			    mapTypeId: 'roadmap',
			    mapTypeControl:false,
			    streetViewControl:false,
			    navigationControl:false
		};
		var map = new google.maps.Map(document.getElementById("map"), myOptions);
		$(".map").not($(this)).each(function(event){
			var ll = new google.maps.LatLng($(this).attr('latitude') ,$(this).attr('longitude'));
			var marker = new google.maps.Marker({
		 		map: map,
		 		position: ll
		    });
		});
		var image = new google.maps.MarkerImage('../res/images/marker_greenA.png');

		var marker = new google.maps.Marker({
			icon: image,
	 		map: map,
	 		position: latlng
	    });
  });
    
  $(document).keyup(function(e){
		if(e.which == 27){
			var temp= $(".map1,#map").is(":visible");//是否可见
			if(!temp){
				return false;
			}
			$(".map1,#map").hide();
		}
	});
  
  $(".close_store").click(function(event){
	  event.preventDefault();
	  var type = $(this).attr("type");
	  if(type == "store_yc"){
		  $(this).attr("type","store_xs");
		  $(".storeclose").hide();
		  $(".word_dg").html('显示未营业店铺');
		  $(".hide_dg").attr("class",'hide_dg1');
	  }
	  if(type == "store_xs"){
		  $(this).attr("type","store_yc");
		  $(".storeclose").show();
		  $(".word_dg").html('隐藏未营业店铺');
		  $(".hide_dg1").attr("class",'hide_dg');
	  }
  });
	/*
	 * 
	 * 12.02.06
	 * 
	 */
	//s
	var all = $(window).height();
	var header = $(".mohu-top").height();
	var footer = $(".mohu-bottom").height();
	var height = all-(header+footer)-48;
	$('.shishi').css('height',height+"px");
	
	//select
	 var instance_trad = '#trading_'+js_context.aid;
	 var instance_somo = '.somo_'+js_context.taid;
	 var map_somoid = js_context.somoid;
	 
	 var map_taid = js_context.taid;
	 $('.search_map').click(function(event){
		 event.preventDefault();
		 var url = $(this).attr("href");
		 if(map_somoid){
			 self.location = url+'?somoid='+map_somoid;
			 return false;
		 }
		 self.location = url+'?taid='+map_taid;
	});
	 
	//order
	$("#sales").mouseover(function(event){
		$('#sales .default_order').show();
	});
	
	$("#sales").mouseleave(function(event){
		$('#sales .default_order').hide();
	});
	
	//ask
	$(".doubt .content").click(function(){
		var data = $.trim($(this).attr("value"));
		if(data == '对搜索页内容有意见和建议？请给我们留言吧！' ){
			$(this).attr("value","");
		}
	});
	
	$(".doubt .content").blur(function(){
		var data = $.trim($(this).attr("value"));
		if(!data){
			$(this).attr("value","对搜索页内容有意见和建议？请给我们留言吧！");
		}
	});
	$("#ask_tj").click(function(event){
		event.preventDefault();
		var url = $(this).attr('url');
		var title = $('.title').children('option:selected').val();
		var type = $(this).attr('types');
		var content = $('.content').val();
		if(content == ''||content == '对搜索页内容有意见和建议？请给我们留言吧！'){
			alert('请输入您的问题！')
			return false;
		}
		if(content.length < 6){
			alert('请您仔细阐述您的问题！')
			return false;
		}
		$.get(url,{ "title" : title,'content':content,'type':type}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('提交失败');
				return false;
			}
			if(data.error == 'notlogin'){
				alert('请先登录!');
				return false;
			}
			if(data.error=='insertfalse'){
				alert('提交问题失败,页面将马上刷新!');
				self.location.reload;
				return false;
			}
			if(data.error=='time'){
				alert('请您半小时后在提交');
				return false;
			}
			self.location = js_context.base_url+'user/ask';
		},"json");
	});
	
	//search页级联
	$('.area-rest').mouseover(function(event){
		$('.tsd1').show();
		$(this).mouseleave(function(event){
			$('.tsd1').hide();
		});
	});
	$('#phq').mouseover(function(event){
		$('.area').show();
		$(this).mouseleave(function(event){
			$('.area').hide();
		});
	});
	 
	$('.area li').click(function(event){
		event.preventDefault();
		$('.area').hide();
		var _this = this;
		var aid = $(_this).attr("aid");
		var areaname = $(_this).find("a").html();
		var url = js_context.base_url+"ajax/search/trading";
		$('.areaname').html(areaname);
		$('.tsd2').show();
		$(".aid_loading").show();
		$('html,body').animate({scrollTop: '0px'}, 800);
		$.get(url, { "aid" : aid }, function(result){
			$(".aid_loading").hide();
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('查询失败');
				return false;
			}
			var html = '';
			html += '<ul style="margin-top:-2px;" class="tradinfo trad_'+result.aid+' hide" aid="'+result.aid+'" >';
			for(var i=0;i<data.length;i++){
				html += '<li class="trading_'+result.aid+'" taid=';
				html += data[i].taid;
				html += '><a href="javascript:void(0)" title='+data[i].name+'>';
				html += data[i].name.substr(0,5);
				html += '</a></li>';
			}
			html +='</ul>';
			
			$('.tradingname').html('请选择');
			$('.somoname').html('请选择');
			$("#djq").append(html);
			$('.trad_'+result.aid).show();
			$('#djq').mouseover(function(event){
				var trad_this = this
				 $('.trad_'+result.aid).show();
				 $(trad_this).mouseleave(function(event){
					 $('.trad_'+result.aid).hide();
				 });
			 });
			
			var div = '.trading_'+result.aid;
			$(div).click(function(event){
				event.preventDefault();
				$('html,body').animate({scrollTop: '0px'}, 800);
				$('.tsd2').hide();
				$('.trading , .tradinfo').hide();
				var trad_li_this = this;
				var taid = $(trad_li_this).attr('taid');
				var url = js_context.base_url+"ajax/search/somoarr";
				var trad_name = $(trad_li_this).find("a").html();
				$('.tradingname').html(trad_name);
				$('.tradingname').attr('title',trad_name);
				$(".taid_loading").show();
				$.get(url, { "taid" : taid }, function(result){
					$(".taid_loading").hide();
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					var data = result.message;
					if(!data){
						alert('查询失败');
						return false;
					}
					var html = '';
					if(data == ''){
						$(".awx").show();
						$(".direction,#bhg").remove();
						setTimeout("window.location.href='"+js_context.base_url+"search?taid="+result.taid+"'", 3000);
						return false;
					}else{
						$('.tsd3').show();
						html += '<ul style="margin-top:-2px;" class="somodata somo_'+result.taid+' hide " taid="'+result.taid+'" >';
						for(var i=0;i<data.length;i++){
							html += '<li class="somoid_'+result.taid+'" somoid=';
							html += data[i].somoid;
							html += '><a href="javascript:void(0)" title='+data[i].name+'>';
							html += data[i].name.substr(0,5);
							html += '</a></li>';
						}
						html +='</ul>';
					}
					$('.direction').show();
					$('.tradingname').attr("href",js_context.base_url+'search?taid='+result.taid);
					$('.somoname').html('请选择');
					$("#bhg").append(html).show();
					$(".somoinfo,.somodata").not('.somo_'+result.taid).remove();
					$('.somo_'+result.taid).show();
					$('#bhg').mouseover(function(event){
						var somo_this = this
						 $('.somo_'+result.taid).show();
						 $(somo_this).mouseleave(function(event){
							 $('.somo_'+result.taid).hide();
						 });
					 });
					
					var div1 = '.somoid_'+result.taid;
					$(div1).click(function(event){
						event.preventDefault();
						$('html,body').animate({scrollTop: '0px'}, 800);
						$(".somoinfo,.somodata").hide();
						$(".awx").show();
						var somoid = $(this).attr('somoid');
						setTimeout("window.location.href='"+js_context.base_url+"search?somoid="+somoid+"'", 3000);
					});
				},"json");
			});
		},"json");
	});
	$('#djq').mouseover(function(event){
		$('.trading').show();
		$(this).mouseleave(function(event){
			$('.trading').hide();
		});
	});
	
	$(".trading li").click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollTop: '0px'}, 800);
		$('.tsd2').hide();
		$('.trading').hide();
		var trad_li_this = this;
		var taid = $(trad_li_this).attr('taid');
		var url = js_context.base_url+"ajax/search/somoarr";
		var trad_name = $(trad_li_this).find("a").html();
		$('.tradingname').html(trad_name);
		$('.tradingname').attr('title',trad_name);
		$(".taid_loading").show();
		$.get(url, { "taid" : taid }, function(result){
			$(".taid_loading").hide();
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('查询失败');
				return false;
			}
			var html = '';
			if(data == ''){
				$(".awx").show();
				$(".direction,#bhg").remove();
				setTimeout("window.location.href='"+js_context.base_url+"search?taid="+result.taid+"'", 3000);	
				return false;
			}else{
				$('.tsd3').show();
				html += '<ul style="margin-top:-2px;" class="somodata somo_'+result.taid+' hide " taid="'+result.taid+'" >';
				for(var i=0;i<data.length;i++){
					html += '<li class="somoid_'+result.taid+'" somoid=';
					html += data[i].somoid;
					html += '><a href="javascript:void(0)" title='+data[i].name+'>';
					html += data[i].name.substr(0,5);
					html += '</a></li>';
				}
				html +='</ul>';
			}
			$('.direction').show();
			$('.tradingname').attr("href",js_context.base_url+'search?taid='+result.taid);
			$('.somoname').html('请选择');
			$("#bhg").append(html).show();
			$(".somoinfo,.somodata").not('.somo_'+result.taid).remove();
			$('.somo_'+result.taid).show();
			$('#bhg').mouseover(function(event){
				var somo_this = this
				 $('.somo_'+result.taid).show();
				 $(somo_this).mouseleave(function(event){
					 $('.somo_'+result.taid).hide();
				 });
			 });
			
			var div1 = '.somoid_'+result.taid;
			$(div1).click(function(event){
				event.preventDefault();
				$('html,body').animate({scrollTop: '0px'}, 800);
				$(".somoinfo,.somodata").hide();
				$(".awx").show();
				var somoid = $(this).attr('somoid');
				setTimeout("window.location.href='"+js_context.base_url+"search?somoid="+somoid+"'", 3000);
			});
		},"json");
	});
	
	$('#bhg').mouseover(function(event){
		$(instance_somo).show();
		$(this).mouseleave(function(event){
			$(instance_somo).hide();
		});
	});
	
	$(".somoinfo li").click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollTop: '0px'}, 800);
		$('.tsd3').hide();
		$(".somoinfo").hide();
		var somo_li_this = this;
		$(".awx").show();
		var somoid = $(this).attr('somoid');
		setTimeout("window.location.href='"+js_context.base_url+"search?somoid="+somoid+"'", 3000);
	});
	
	if(s){
		var input = document.getElementById('index_s_input');
	    var defaultBounds = new google.maps.LatLngBounds(
			  new google.maps.LatLng(40.067618, 116.282644),
			  new google.maps.LatLng(39.818331, 116.507298)
		);var options = {
			  bounds: defaultBounds
			};
			autocomplete = new google.maps.places.Autocomplete(input, options);
			google.maps.event.addListener(autocomplete, 'place_changed', function() {
				  var place = autocomplete.getPlace();
				  $(".lat").val(place.geometry.location.lat());
				  $(".lng").val(place.geometry.location.lng());
				});	
			$("#index_s_input").keypress( function(e) {
				var key = window.event ? e.keyCode : e.which;
				if(key.toString() == "13"){
					var lat = js_context.lat;
					var lng = js_context.lng;
					if(lat == $(".lat").val() && lng == $(".lng").val()){
						return false;
					}
					var lat = $(".lat").val();
					var lng = $(".lng").val();
					if(!lat ||!lng){
						return false;
					}
				}
			});
	}

	
});
